package cn.nawang.ebeim.client.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.nawang.ebeim.client.util.PropertiesConstants;
import cn.nawang.ebeim.client.util.PropertiesUtil;

public class ClientConfiguration {

  static {
    try {
      setProperties(PropertiesUtil.readAll());
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
    }
  }

  private static final Logger LOG = LoggerFactory.getLogger(ClientConfiguration.class);

  private static String customerId = null;
  private static String terminalId = null;
  public static Map<String,String> encriptKeyMap = new HashMap<String,String>();
  public static Map<String,DataSource> isRunningList = new HashMap<String,DataSource>();
  
  public static String getTerminalId() {
    return terminalId;
  }

  public static void setTerminalId(String terminalId) {
    ClientConfiguration.terminalId = terminalId;
  }

  public static String getCustomerId() {
    return customerId;
  }

  public static void setCustomerId(String customerId) {
    ClientConfiguration.customerId = customerId;
  }

  private static Map<String, String> properties;

  private static List<StorageServer> storageServers = new ArrayList<StorageServer>();

  public static List<StorageServer> getStorageServers() {
    return storageServers;
  }

  public static void setStorageServers(List<StorageServer> storageServers) {
    ClientConfiguration.storageServers = storageServers;
  }

  public static Map<String, String> getProperties() {
    return properties;
  }

  public static void setProperties(Map<String, String> properties) {
    ClientConfiguration.properties = properties;
  }

  public static String getTempFilePrefix() {
    return properties.get(PropertiesConstants.TEMP_FILE_PREFIX);
  }

  public static String getWorkingPath() {
    return properties.get(PropertiesConstants.WORKING_PATH);
  }

  public static int getQueueSize() {
    return Integer.valueOf(properties.get(PropertiesConstants.QUEUE_SIZE));
  }

  public static int getMaxUploadRetries() {
    return Integer.valueOf(properties.get(PropertiesConstants.MAX_UPLOAD_RETRIES));
  }

  public static String getApiHost() {
    return  "http://" +properties.get(PropertiesConstants.API_IP)+":"+properties.get(PropertiesConstants.API_PORT);
    //return properties.get(PropertiesConstants.API_HOST);
  }

  public static int getSessionTime() {
    return Integer.valueOf(properties.get(PropertiesConstants.SESSION_TIME));
  }

  public static int getMaxServerRetries() {
    return Integer.valueOf(properties.get(PropertiesConstants.MAX_SERVER_RETRIES));
  }

  public static long getServerRetriesSleep() {
    return Long.valueOf(properties.get(PropertiesConstants.SERVER_RETRIES_SLEEP)) * 1000;
  }

  public static long getDatasourceCheck() {
    return Long.valueOf(properties.get(PropertiesConstants.DB_DATASOURCE_CHECK_TIME)) * 1000;
  }

  public static String getDbDumpDir() {
    return properties.get(PropertiesConstants.DB_DUMP_DIR);
  }

  public static String getLocalBackupPath() {
    return properties.get(PropertiesConstants.LOCAL_BACKUP_PATH);
  }

  public static Integer getLocalBackupMax() {
    return Integer.valueOf(properties.get(PropertiesConstants.LOCAL_BACKUP_MAX));
  }

  public static Long getReadLimit() {
    return Long.valueOf(properties.get(PropertiesConstants.READ_LIMIT));
  }

  public static Long getWriteLimit() {
    return Long.valueOf(properties.get(PropertiesConstants.WRITE_LIMIT));
  }

  public static Long getCheckInterval() {
    return Long.valueOf(properties.get(PropertiesConstants.CHECK_INTERVAL));
  }


}
